;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Version 1.1
; Author: Walter Krmbring
; IP of the PC: 192.168.10.253
; Date: 5.01.2007
; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 

; NexaSunRise is as its name indicates, an application for Windows that can control RF devices like NEXA's and
; InterTechno's radio receiver modules according to the sunset/sunrise at your geographical location.
; Recently interfacing with EventGhost (EG) was added. This gives more or less unlimited possibilities since all devices
; controlled by EG can then by triggered by events sent from this application.

; NexaSunRise has no real useful GUI itself since it is more of a service you "set & forget". In combination with
; EG you can use the nice GUI of EG or you can create web pages according to your personal needs.

; The idea behind this application is that you might have outdoor and indoor lights that needs to be controlled
; automatically depending on sunrise/sunset and daylight savings.

; You might need to turn lights ON at sunset and then turn them OFF later in the evening or following night at a specified time,
; as example at 23.00 during weekdays but 01.00 during weekends.  

; You might also wish to turn the outdoor lights ON in the morning at a specified time, let's say at 06.00 during
; weekdays (provided this is before the sunrise) and then turn everything OFF again when sunrise comes.

; Another usage could be for indoor lamps in windows or in living room etc. Normally it gets darker indoor a bit
; earlier during sunset and the darkness also stays longer during sunrise. To compensate for this, it's possible to
; define offset settings for those module addresses where this is needed. 

; The application also supports detection of incoming Skype calls. Sometimes you are not always around your computer
; and it could be nice to see a lamp or some other device indicate that you received a call. Especially if you have
; your computers on a different floor in your house.

; Pre-requisite is of course that Skype is installed and started in the same computer as NexaSunRise.

; The application uses the following functions to provide the above functionality;

; - geographical position (latitude/longitude settings for sunrise/sunset calculation for the site you are controlling)
; - calculation in run-time of sunset/sunrise for each day of the year
; - automatic corrections for daylight savings
; - automatic correction for public holidays (fixed and variable (requires your attention with manual updating once a year))
; - logging of all actions
; - time triggered ON/OFF commands
; - individual settings for each module address for each day of the week

 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; History:
;
; 24.07.2007  Modified the function for sending events to EventGhost thru the web interface
;
; 03.07.2007  Added support for sending events to EventGhost. Now more or less unlimited possibilities are there :)
;
; 30.06.2007  Added alternative method for checking daylight savings (via operating system or via internal calculation)
;
; 08.06.2007  Added settings to adjust the synchronization interval
;
; 24.05.2007  Added support for Telldus Technologies Tellstick. Requires installation of software with driver from Telldus
;
;	      Read more here: http://telldus.se/index.php
;
;         To make it work, you have to configure "Telldus" with the devices you want NexaSunRise to control
;	      If you for instance want to use A2 to control the outdoor lights, you need to create an A2 device
;         in Telldus too.
;	      Telldus supports various brands of devices (Nexa, Proove, Sartano, Waveman...) so NexaSunRise is not
;         limited to control only Nexa devices anymore.
;
; 01.05.2007  Bug fix regarding holiday handling. Messed it up...
; 
; 21.04.2007  Added support for addresses D1-D3 too. Common maintenance, clean-up and optimizations
;
; 11.04.2007: Added improved handling of holidays. The following rules are now valid and implemented:
;             - if today is a normal weekday and tomorrow is a holiday, use time settings for Friday
;             - if today and tomorrow are holidays, use time settings for Saturday
;             - if today is a holiday and tomorrow normal weekday, use time settings for Sunday
;
;             Re-worked the functions so its now possible to have the light turned on the whole night with only
;             one setting needed. You just have to define the time when you want the lamp to be turned on in the
;             morning (as example 0700)
;             In this example with a lamp, it will work accordingly:
;             - the lamp will be turned ON at 0700 if this is before sunrise
;             - the lamp will be turned OFF at sunrise
;             - the lamp is turned ON again at sunset
;             - the lamp is ON the whole evening and the following night until sunrise
;
; 30.03.2007: Added logging of calculated/expected time for sunrise/sunset
;             Added function for capturing IR callbacks using the "USB-UIRT" transceiver. Only for my testing
;             purposes.
;
; 26.03.2007: Bug fix regarding daylight savings function
;
; 21.03.2007: Added the following configurable features;
;             - synchronization of controls at application start-up
;             - synchronization of controls continues during run-time or only at the specified ON/OFF times
;             - number of transmissions for each command (bursts) 
;             - the minimum on-period left required to turn the control on since it makes no sense to turn on
;             lights if there is only a short period left before they will be turned off again. If time left
;             will be less than the specified minimum on-period, the light will not be turned on at all
;
; 21.01.2007: Added support for monitoring incoming Skype calls
;
; 05.01.2007: Added support for the "USB-UIRT" transceiver to be used in combination with a pyramid IR/RF converter
;

